module Cube;

import derelict.opengl.gl;
import std.stdio;

struct Vertex{
	public float x, y, z;
}

class Cube{
	Vertex[] vertices;
	
	this(){
		writefln("asdasd");
		/*
				 4----- 5
			   / |    / |
		    0 ------1   |
		    |    |  |   |
		    |    7 -|---6
		    |  /    | /
			3-------2
		*/
		addVertex(-1.0f, 1.0f, 1.0f);	//0
		addVertex(1.0f, 1.0f, 1.0f);	//1
		addVertex(1.0f, -1.0f, 1.0f);	//2
		addVertex(-1.0f, -1.0f, 1.0f);	//3
		addVertex(-1.0f, 1.0f, -1.0f);	//4
		addVertex(1.0f, 1.0f, -1.0f);	//5
		addVertex(1.0f, -1.0f, -1.0f);	//6
		addVertex(-1.0f, -1.0f, -1.0f);	//7
	}
	
	void moveBy(float x, float y, float z){
		for (int i = 0; i < 8; i++){
			vertices[i].x += x;
			vertices[i].y += y;
			vertices[i].z += z;
		}
		/+foreach(v; vertices){
			v.x = v.x + x;
			v.y += y;
			v.z += z;
			writefln("%f %f %f", v.x, v.y, v.z);
		}
		foreach(v; vertices){
			writefln("%f %f %f", v.x, v.y, v.z);
		}+/
	}
	
	void draw(){
		
		int[] front = [0,1,2,3];
		int[] back = [4,5,6,7];
		int[] top = [0,4,5,1];
		int[] bottom = [3,7,6,2];
		int[] right = [1,5,6,2];
		int[] left = [0,4,7,3];
		glBegin(GL_QUADS);
			//glNormal3f(0.0f, 0.0f, 1.0f);
			glColor3f(0.5, 0.5, 0.4);
			foreach(v; front){
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
			foreach(v; back){
				glColor3f(0.2, 0.5, 0.4);
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
			foreach(v; top){
				glColor3f(0.7, 0.5, 0.4);
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
			foreach(v; bottom){
				glColor3f(0.9, 0.5, 0.4);
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
			foreach(v; left){
				glColor3f(0.5, 0.1, 0.4);
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
			foreach(v; right){
				glColor3f(0.5, 0.9, 0.4);
				glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
			}
		glEnd();
	}
	private:
		void addVertex(float x, float y, float z){
			vertices ~= Vertex(x,y,z);
		}
}